package java集合.ArrayListDemo;

import java.util.*;

public class ArrayListSourceCode{

    /**
     * 模拟从数据库中拿到Banner集合
     */
    private static List<Banner> list=new ArrayList<>();
    static {
        Banner banner5 = new Banner(5, "5");
        Banner banner3 = new Banner(3, "3");
        Banner banner1 = new Banner(1, "1");
        Banner banner4 = new Banner(4, "4");
        Banner banner2 = new Banner(2, "2");
        list.add(banner5);
        list.add(banner3);
        list.add(banner1);
        list.add(banner4);
        list.add(banner2);

    }

    public static void main(String[] args) {
        System.out.println("排序之前");
        list.forEach(v-> System.out.println(v));

        Collections.sort(list);//集合的sort是升序排序的

        System.out.println("排序之后");
        list.forEach(v-> System.out.println(v));

        int index = Collections.binarySearch(list, new Banner(4, "4"));
        System.out.println("获取到的索引"+index);
    }
}


